package com.njwb.predicate;
import org.springframework.cloud.gateway.handler.predicate.AbstractRoutePredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.GatewayPredicate;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
@Component
public class CheckOrgRoutePredicateFactory extends AbstractRoutePredicateFactory<CheckOrgRoutePredicateFactory.Config> {
    public CheckOrgRoutePredicateFactory() {
        //传递配置对象
        super(Config.class);
    }
    @Override
    public Predicate<ServerWebExchange> apply(CheckOrgRoutePredicateFactory.Config config) {
        return new GatewayPredicate() {
            @Override
            public boolean test(ServerWebExchange serverWebExchange) {
                if (config.getName().equals("njwb")) {
                    return true;
                }
                return false;
            }
        };
    }
    @Override
    public List<String> shortcutFieldOrder() {
        //绑定name值
        return Collections.singletonList("name");
    }
    public static class Config {//断言中的配置名称
        private String name;
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
    }
}
